# 路径总和2

# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def pathSum(self, root, targetSum):
        """
        :type root: TreeNode
        :type targetSum: int
        :rtype: List[List[int]]
        """
        result = list()
        comb = list()

        def DFS(root, targetSum):
            if not root:
                return

            comb.append(root.val)
            targetSum -= root.val
            if not root.left and not root.right and targetSum == 0:
                result.append(comb[:]) # 将各个元素作为拷贝，如果直接赋值为comb则会导致元素都为空
            DFS(root.left, targetSum)
            DFS(root.right, targetSum)
            comb.pop()
            targetSum += root.val

        DFS(root, targetSum)
        return result


lis = [[1,2,3],[4,5]]
result1 = [100]
result2 = [100]
result3 = [100]
result1.extend(lis)
result2.append(lis)
result3.append(lis[:])
print(result1)
print(result2)
print(result3)